package com.osfw.activiti.service.history.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.osfw.activiti.domain.ProcessApproval;
import com.osfw.activiti.domain.ProcessExecResult;
import com.osfw.activiti.domain.ProcessNodeInfo;
import com.osfw.activiti.entity.history.ActHiProcinst;
import com.osfw.activiti.entity.resource.ActReProcdef;
import com.osfw.activiti.mapper.history.ActHiProcinstMapper;
import com.osfw.activiti.service.history.IActHiProcinstService;
import com.osfw.activiti.service.resource.IActReProcdefService;
import com.osfw.system.entity.manage.SysUser;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * 流程实例表 服务层实现
 */
@Service
public class ActHiProcinstServiceImpl extends ServiceImpl<ActHiProcinstMapper, ActHiProcinst> implements IActHiProcinstService {

    /**
     * 初始化流程实例信息
     *
     * @param title     标题
     * @param busiType  业务类型
     * @param busiKey   业务KEY
     * @param startUser 发起人
     * @param startTime 开始时间
     * @param procdef   流程信息
     * @param startNode 开始节点
     */
    @Override
    public ActHiProcinst init(String title, String busiType, String busiKey, SysUser startUser, Date startTime, ActReProcdef procdef, ProcessNodeInfo startNode) {
        ActHiProcinst procinst = new ActHiProcinst();
        procinst.setProcDefId(procdef.getProcDefId());
        procinst.setTitle(title);
        procinst.setBusiType(busiType);
        procinst.setBusiKey(busiKey);
        procinst.setStartUser(startUser.getUserId());
        procinst.setStartTime(startTime);
        procinst.setStartActKey(startNode.getKey());
        boolean save = save(procinst);
        if (save) {
            return procinst;
        }
        return null;
    }

    @Override
    public ActHiProcinst finish(ProcessApproval approval, SysUser sysUser, Date currentTime, ProcessExecResult execResult) {
        return null;
    }

}
